package de.gwtprime.client.activities;

import java.util.List;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.web.bindery.requestfactory.shared.Receiver;

import de.gwtprime.client.ClientFactory;
import de.gwtprime.client.places.ArticleOverviewPlace;
import de.gwtprime.client.views.ArticleOverviewView;
import de.gwtprime.client.viewsStatic.NavigationViewImpl.Section;
import de.gwtprime.shared.requestFactory.ArticleProxy;

public class ArticleAcitvityOverview extends PrimeAbstractActivity{
	
	private ClientFactory clientFactory;

	private String name;
	
	public ArticleAcitvityOverview(ArticleOverviewPlace place, ClientFactory clientFactory) {
		this.name = place.getName();
		this.clientFactory = clientFactory;
	}
	@Override
	public void start(final AcceptsOneWidget panel, EventBus eventBus) {
		
		clientFactory.getNavigationView().activateSection(Section.ARTICLE);
		clientFactory.getRequestFactory().articleRequest().loadLatestArticles(10).fire(new Receiver<List<ArticleProxy>>() {

			@Override
			public void onSuccess(List<ArticleProxy> response) {
				
				ArticleOverviewView articleOverview = clientFactory.getArticleOverviewWidget();
				articleOverview.setArticles(response);
				panel.setWidget(articleOverview);
				
			}
		});
		
	}

}
